//
//  XWMainViewController.swift
//  新浪 weibo
//
//  Created by xuwei on 16/1/18.
//  Copyright © 2016年 xuwei. All rights reserved.
//

import UIKit

class XWMainViewController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = XWTabBar()
        tabBar.composeButtonClickClourse = {
            print("点击添加")
        }
        self.setValue(tabBar, forKeyPath: "tabBar")
        
        
        addChildViewControllers()
    }
    
    func addChildViewControllers() {
        addChildViewController(XWHomeTableViewController(), title: "首页", imgNamed: "tabbar_home")
        addChildViewController(XWMessageTableViewController(), title: "消息", imgNamed:"tabbar_message_center")
        addChildViewController(XWDiscoverTableViewController(), title: "发现", imgNamed: "tabbar_discover")
        addChildViewController(XWProfileTableViewController(), title: "我", imgNamed: "tabbar_profile")
    }
    
    
    
    func addChildViewController(childController: UIViewController,title:String, imgNamed:String) {
        
        childController.title = title
        
        childController.tabBarItem.image = UIImage(named: imgNamed)
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgNamed)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        let attributed = [NSForegroundColorAttributeName:UIColor.orangeColor()]
        
        childController.tabBarItem.setTitleTextAttributes(attributed, forState: UIControlState.Selected)
        
        addChildViewController(XWNavigationController(rootViewController: childController))
        
    }
    
}
